Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripting/lua): correct LuaNativeContext constructor #2286

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

Ehbw
Copy link
Contributor

@Ehbw Ehbw commented Nov 25, 2023

Fixes #2183 and the forums post referenced (SetPlayerRoutingBucket, SetEntityRoutingBucket natives)

Repro

RegisterCommand("setBucket", function(source, args)
    SetPlayerRoutingBucket(tostring(source), (tonumber(args[1] or "100") or 100))
end, false)

RegisterCommand("getBucket", function(source)
    print(("You are in bucket %s"):format(GetPlayerRoutingBucket(tostring(source))))
end, false)

@Ehbw Ehbw force-pushed the fix/oal-arguments branch 2 times, most recently from bdd8733 to d68c321 Compare November 25, 2023 19:33
Copy link
Contributor

@thorium-cfx thorium-cfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, only a small style concern. If you're able could you also check if it has other uninitialized fields?

LUA_INLINE LuaNativeContext(void*, int numArguments)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of renaming a fine parameter name, you can initialize them like this (preferred in C++):

LUA_INLINE LuaNativeContext(void*, int numArguments)
	: numArguments(numArguments)
	, numResults(0)
{
}

Copy link
Contributor

@gottfriedleibniz gottfriedleibniz Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That struct inherits fxNativeContext.

The amount of bloat/cruft in this area is quite high.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of renaming a fine parameter name, you can initialize them like this (preferred in C++):

LUA_INLINE LuaNativeContext(void*, int numArguments)
	: numArguments(numArguments)
	, numResults(0)
{
}

I originally did this, however it required me to redefine those fields again in the struct.

Copy link
Contributor

@thorium-cfx thorium-cfx Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️I see... just do this->numArguments = numArguments for now then, we'll get to it later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Ehbw Ehbw force-pushed the fix/oal-arguments branch from d68c321 to 33173c1 Compare November 28, 2023 14:36
@Ehbw Ehbw force-pushed the fix/oal-arguments branch from 33173c1 to 3f9b239 Compare November 28, 2023 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR is enqueued for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I stupid
4 participants